package com.um.jdy.platform.platform.controller;

import com.um.jdy.common.device.entity.dto.StationDTO;
import com.um.jdy.common.device.entity.po.Station;
import com.um.jdy.common.device.entity.vo.StationVO;
import com.um.jdy.common.platform.entity.po.CompanyRole;
import com.um.jdy.platform.platform.entity.dto.CompanyRoleTreeDTO;
import com.um.jdy.platform.platform.entity.dto.RolePageDTO;
import com.um.jdy.platform.platform.manager.CompanyRoleManager;
import com.um.jdy.platform.station.entity.dto.StationPageDTO;
import com.um.jdy.platform.station.entity.vo.StationItemVO;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.LoginRequired;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 控制器：系统角色表
 */
@RestController
@RequestMapping("/api/v1/cms/platform/role")
@Api(tags = "RoleController", description = "系统角色表")
@ApiPermission("company_role")
@TokenRequired
public class CompanyRoleController extends BaseController<CompanyRoleManager> {

    @ApiPermission("menu_tree")
    @ApiOperation("菜单")
    @GetMapping("/{roleId}/menu_tree")
    public Response getMenuTree(@NotNull @PathVariable String roleId){
        return manager.getMenuTree(roleId);
    }

    /**
     * 查询分页
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation("查询分页")
    @PostMapping("/page")
    public Response<Page<CompanyRole>> getStationPage(@RequestBody RolePageDTO params){
        PageParams pageParams = params.toPageParams(new String[]{"name"},new String[]{"name"});
        pageParams.getCondition().put("orderby","create_time desc");
        return manager.getPage(pageParams);
    }

    @ApiPermission("add")
    @ApiOperation("新增")
    @PostMapping
    public Response add(@RequestBody CompanyRoleTreeDTO dto) {
        return manager.addEntity(dto.getRole(),dto.getMenuIds());
    }

    @ApiPermission("update")
    @ApiOperation("更新")
    @PutMapping({"{id}"})
    public Response update(@PathVariable String id, @RequestBody CompanyRoleTreeDTO dto) {
        return manager.updateEntity(id, dto.getRole(),dto.getMenuIds());
    }

    @ApiPermission("delete")
    @ApiOperation("删除")
    @DeleteMapping({"{id}"})
    public Response delete(@PathVariable String id) {
        return manager.delete(id);
    }

    @ApiPermission("delete_all")
    @ApiOperation("批量删除")
    @DeleteMapping
    public Response deleteIds(@ApiParam(value = "删除的id",required = true) @RequestBody List<String> ids) {
        return manager.deleteIds(ids);
    }

}
